package common
{
    import cn.flashk.controls.Alert;
    
    import common.events.ModulesDataEvent;
    import common.message.PublicNotice;
    
    import flash.display.StageQuality;
    import flash.events.Event;
    
    import kernel.core.Core;
    import kernel.core.KernelStart;
    import kernel.eventCenter.EventCenter;
    import kernel.events.ModuleEvent;
    import kernel.server.HttpServer;
    import kernel.server.Server;

    public class AllModulesShareInit
    {
        public function AllModulesShareInit()
        {
        }

        public static function init():void
        {
			
//			Core.stage.quality = StageQuality.MEDIUM;
			
			AppLayers.init();
            EventCenter.addEventListener (ModuleEvent.ALL_INIT_COMPLETE , onFirstInitOK);
            PublicNotice.init ();
			API.uploadHttpServer = new HttpServer();
			var xml:XML = KernelStart.netConfigXML;
			API.uploadHttpServer.init(String(xml.httpUpload.server));
			
			Core.serverAddListener(Event.CLOSE,onSocketClose);
			
        }
		
		private static function onSocketClose(event:Event):void
		{
			Alert.show("网络出现故障，与服务器的连接已经断开。请尝试重新刷新页面",Core.stage,null,"网络异常",null,null,true);
			
		}
		
        //所有模块初始化完成后请求数据
        private static function onFirstInitOK(event:Event):void
        {
            EventCenter.removeEventListener (ModuleEvent.ALL_INIT_COMPLETE , onFirstInitOK);
//            Server.ins.
        }

        //发送数据已经拿到的消息
        private static function onGetAllData(event:Event = null):void
        {
            EventCenter.dispatchEvent (new ModulesDataEvent (ModulesDataEvent.FIRST_DATA_GET_COMPLETE));
        }

    }
}
